package mware_lib;

import java.io.Serializable;

public class NameServiceMessage implements Serializable{

    private static final long serialVersionUID = 5419020986729013393L;
    private String type;
    private String name;
    private int port;
    private String host;
    private String servantName;
    private int hash;
    private String splitString = Config.splitString;

    public NameServiceMessage(String type, String name, String host, int port, String servantName, int hash) {
        super();
        this.type = type;
        this.name = name;
        this.host = host;
        this.port = port;
        this.servantName = servantName;
        this.hash = hash;

    }

    public NameServiceMessage(String type, String name) {
        super();
        this.type = type;
        this.name = name;
    }

    public String getType() {
        return type;
    }
    public String getName() {
        return name;
    }
    public Object getReference() {
        return this;
    }

    public int getPort() {
        return port;
    }

    public String getHost() {
        return host;
    }

    public int getHash() {
        return hash;
    }

    public String getServantName() {
        return servantName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        NameServiceMessage that = (NameServiceMessage) o;

        if (hash != that.hash) return false;
        if (port != that.port) return false;
        if (servantName != null ? !servantName.equals(that.servantName) : that.servantName != null) return false;
        if (host != null ? !host.equals(that.host) : that.host != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = host != null ? host.hashCode() : 0;
        result = 31 * result + port;
        result = 31 * result + (servantName != null ? servantName.hashCode() : 0);
        result = 31 * result + hash;
        return result;
    }

    @Override
    public String toString() {
        return   "Type: " + type + splitString +
                "Name: " + name + splitString +
                "Host: " + host + splitString +
                "Port: " + port + splitString +
                "ClassName: " + servantName +
                "hash" + hash;
    }

    public String sendMsg() {
        return   type + splitString +
                name + splitString +
                host + splitString +
                port + splitString +
                servantName + splitString +
                hash;
    }
}
